package com.csist.dao;

import com.csist.bean.Classes;
import com.csist.util.JDBCUtil;

import java.sql.*;
import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName ClassesDao
 * @Description TODO
 * @Author User
 * @Date 2021/6/26 15:36
 * @ModifyDate 2021/6/26 15:36
 * @Version 1.0
 */
public class ClassesDao {
    public List<Classes> getClassesByTeacherId(int id){
        Connection conn = JDBCUtil.getConnection();
        PreparedStatement ps = null;
        ResultSet rs = null;
        String sql = "select * from classes where t_id = ?";
        List<Classes> lists = new ArrayList<>();
        try {
            ps = conn.prepareStatement(sql);
            ps.setInt(1,id);
            rs = ps.executeQuery();
            while (rs.next()){
                lists.add(new Classes(rs.getInt(1),rs.getString(2),rs.getDate(3),rs.getInt(4)));
            }
            if (lists.size()==0){
                lists = null;
            }
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        } finally {
            JDBCUtil.close(conn,ps,rs);
        }
        return lists;
    }
}
